#include <iostream>
using namespace std;

enum privileges
{
    PUB,
    PRI,
    PRO
};

class member1
{
    
    int a = 0;

public:
    member1()
    {
        cout << "member1 构造函数 被调用" << endl;
    }
};

class member2
{
    int a = 0;

public  :
    member2()
    {
        cout << "member2 构造函数 被调用" << endl;
    }
};

class base
{
private:
    int m = 0;

protected:
    int p = 0;

public:
    int q = 0;
    //base() : m(0), p(0), q(0) {};
    base(int _m) : m(_m), p(0), q(0) {}
    base(int _m, int _p, int _q) : m(_m), p(_p), q(_q) {}
    ~base()
    {
        cout << "base destructor called" << endl;
    }


    int operator+(int n)    //重载运算符
    {
        cout << "+" << endl;
        m = m + n;
        return m;
    }
    //base(const base &obj); // 拷贝构造

    void show_num(void)
    {
        cout << "m = " << m << endl;
    }
};

class derived : public base
{
    //认为最高处隐藏了base的成员变量，在构造时，调用了base的构造函数，并传入参数
private:
    int n = 0;
    //此处的顺序会先调用ber1的构造函数，再调用ber2的构造函数
    member1 ber1;
    member2 ber2;

public:

    derived() : base(10, 20, 30),ber1(),ber2() //调用了base的构造函数，并传入参数，如果base没有默认构造，。此处ber1和ber2的初始化顺序无关，与上面的成员变量顺序有关
    {
        cout << "调用子类构造函数" << endl;
    }
    void show(int x)
    {
        n = x;
        cout << "n = " << n << endl;
    }
};

int main()
{
    cout << "base class" << endl;
    base b(10);
    b + 10;
    b.show_num();
    cout << "derived class" << endl;
    derived der;
    // derived der(99);
    der.show_num();
    der + 10;
    der.show_num();
    der.show(10);
    cout << "end of main()" << endl;
    return 0;
}